#ifndef __USB_V4L2__
#define __USB_V4L2__


#include <stdio.h>
#include "vdma.h"
 

#define  	TRUE			1
#define  	FALSE			0
#define  	FRAME_RATE		30				// 图锟斤拷帧锟斤拷
#define 	FILE_VIDEO 		"/dev/video0"   // 锟斤拷锟斤拷头默锟斤拷锟斤拷锟斤拷
#define  	IMAGEWIDTH    	1920  			// 图锟斤拷锟�
#define  	IMAGEHEIGHT   	1080			// 图锟斤拷锟�
#define  	PIXBYTE   			2



 

#if defined(__cplusplus)
extern "C" {     /* Make sure we have C-declarations in C++ programs */
#endif


/*****************************************************************************
  Function:     锟斤拷始锟斤拷V4l2
  Description:  1锟斤拷锟斤拷始锟斤拷V4l2锟斤拷锟斤拷锟斤拷锟斤拷锟借备锟斤拷
				2锟斤拷锟斤拷video_capability锟斤拷锟斤拷息锟斤拷
				通锟斤拷锟斤拷锟斤拷IOCTL锟斤拷锟斤拷锟酵接匡拷锟斤拷锟斤拷VIDIOC_QUERYCAP锟斤拷询锟斤拷锟斤拷头锟斤拷锟斤拷息锟斤拷
				锟结构锟斤拷v4l2_capability锟斤拷锟叫帮拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷driver锟斤拷card锟斤拷bus_info锟斤拷
				version锟皆硷拷锟斤拷锟斤拷capabilities锟斤拷
				3锟斤拷锟叫撅拷锟斤拷锟斤拷头锟斤拷支锟斤拷锟斤拷锟截革拷式锟斤拷YUV2锟斤拷MJPEG锟斤拷锟斤拷锟斤拷锟斤拷图锟斤拷锟绞斤拷锟斤拷锟狡碉拷杉锟街★拷剩锟�
  Input:        none
  Output:       none
  Return:       none
  Author:       cc
  Modify:
*****************************************************************************/
int init_v4l2(void);


/*****************************************************************************
  Function:     图锟斤拷杉锟�
  Description:  1锟斤拷锟斤拷锟诫缓锟斤拷锟斤拷锟斤拷
				2锟斤拷锟斤拷取每锟斤拷锟斤拷锟斤拷锟斤拷锟较拷锟斤拷锟絤map锟斤拷锟矫伙拷锟秸间。锟斤拷锟斤拷峁癸拷澹�
  Input:        none
  Output:       none
  Return:       none
  Author:       cc
  Modify:
*****************************************************************************/
int v4l2_grab(void);

struct buffer
{
	void * start;
	unsigned int length;
} * buffers;



/*****************************************************************************
  Function:     取锟斤拷图锟斤拷
  Description:  取锟斤拷锟斤拷锟斤拷锟斤拷锟窖撅拷锟斤拷锟斤拷锟侥伙拷锟芥，
				锟斤拷频锟斤拷锟捷达拷诺锟轿伙拷锟斤拷锟絙uffers[n_buffers].start锟侥碉拷址锟斤拷锟斤拷
  Input:        frame_buf锟斤拷len
  Output:       none
  Return:       none
  Author:       cc
  Modify:
*****************************************************************************/

//int get_frame(unsigned short yuyvData[CAM_HSIZE * CAM_VSIZE*2]);
//int get_frame(void **frame_buf, size_t* len,unsigned short yuvDatayuvData[CAM_HSIZE * CAM_VSIZE*2]);
int get_frame(unsigned char yuyvData[CAM_HSIZE * CAM_VSIZE*CAM_PIXELLENGTH]);


/*****************************************************************************
  Function:     停止锟斤拷频锟缴硷拷
  Description:  锟截憋拷锟借备锟斤拷停止锟斤拷频锟缴硷拷
  Input:        none
  Output:       none
  Return:       none
  Author:       cc
  Modify:
*****************************************************************************/
int close_v4l2(void);


/*****************************************************************************
  Function:     锟酵凤拷锟斤拷频帧锟斤拷锟矫筹拷锟斤拷锟斤拷占锟阶硷拷锟斤拷碌锟斤拷锟狡抵★拷锟斤拷锟�
  Description:  锟酵凤拷锟斤拷频帧锟斤拷锟矫筹拷锟斤拷锟斤拷占锟阶硷拷锟斤拷碌锟斤拷锟狡抵★拷锟斤拷锟�
  Input:        none
  Output:       none
  Return:       none
  Author:       cc
  Modify:
*****************************************************************************/
int free_frame();
int usb_camera_initial();
void with8to16(void**yuv_buffer_pointer,size_t* len,unsigned short yuyvData[IMAGEWIDTH*IMAGEHEIGHT]);
void data_convert(char*yuv_buffer_pointer_tmp,unsigned short yuyvData[IMAGEWIDTH*IMAGEHEIGHT]);
#endif //__USB_V4L2__
